package tpe.yana.testp1;

/**
 *
 * @author yana
 */
public class RecursionBaseHanoiConstructor implements HanoiConstructor {
    private int step;

    @Override
    public int construct(Model model, View view) {
        step = 0;
        hanoi(view, model.getHeight(), model.getA(), model.getB(), model.getC());
        return step;
    }

    private void move(Tower a, Tower b) {
        b.push(a.pop());
    }

    private void hanoi(View view, int num, Tower a, Tower b, Tower c) {
        view.printInternal();
        step ++;
        if (num > 0) {
            hanoi(view, num - 1, a, c, b);
            move(a, b);
            hanoi(view, num - 1, c, b, a);
        }
    }

    public int getStep() {
        return step;
    }

}
